﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataStructureSample.ListDs
{
    public class LinkedList<T>
        : IListDs<T>
    {
        private Node<T> head;
        public LinkedList()
        {
            head = null;
        }
        public T this[int index] => throw new NotImplementedException();

        public void Add(T item)
        {
            if (head == null)
            {
                head = new Node<T>(item);
            }
            else
            {
                var temp = head;
                while (true)
                {
                    if (temp.Next != null)
                    {
                        temp = temp.Next;
                    }
                    else
                    {
                        break;
                    }
                }
                temp.Next = new Node<T>(item);
            }
        }

        public void Clear()
        {
            throw new NotImplementedException();
        }

        public void Delete(int index)
        {
            throw new NotImplementedException();
        }

        public T GetEle(int index)
        {
            throw new NotImplementedException();
        }

        public int GetLength()
        {
            throw new NotImplementedException();
        }

        public void Insert(T item, int index)
        {
            var newNode= new Node<T>(item);
            if (index == 0)
            {
                var temp = new Node<T>();
                temp.Next = head;
                head = temp;
            }
            else
            {
                var temp = head;
                for (int i = 0; i < index-1; i++)
                {
                    temp.Next = temp;
                }
                var prev = temp;
                var current = prev.Next;
                prev.Next = newNode;
                newNode.Next = current;
            }
        }

        public bool IsEmpty()
        {
            throw new NotImplementedException();
        }

        public int Locate(T item)
        {
            throw new NotImplementedException();
        }
    }
}
